package com.chixing.work_05;

public class Orderhandle{

    public void handleOrder(Order order){
        while (order.getOrderNum() > 1000){
            Order ordernew = null;
            if (order instanceof Companyorder){
                Companyorder c1 = new Companyorder();
//                Companyorder c2 =(Companyorder)order;
                c1.setOrderId(order.getOrderId());
                c1.setOrderName(order.getOrderName());
                c1.setOrderNum(1000);
                ordernew = c1;
//                System.out.println(order.getOrderId() +" "+ order.getOrderName()+ " " +order.getOrderNum());
            }
            else if(order instanceof Personalorder){
                Personalorder p1 = new Personalorder();
//                Personalorder p2 =(Personalorder)order;
                p1.setOrderId(order.getOrderId());
                p1.setOrderName(order.getOrderName());
                p1.setOrderNum(1000);
                ordernew = p1;
            }
            order.setOrderNum(order.getOrderNum()-1000);
            System.out.println("订单编号："+ordernew.getOrderId() +" 订单名称："+ ordernew.getOrderName()+ " 订单数量：" +ordernew.getOrderNum());
        }
        System.out.println("订单编号："+order.getOrderId() +" 订单名称："+ order.getOrderName()+ " 订单数量：" +order.getOrderNum());

    }

    public static void main(String[] args) {
        Order order1 = new Companyorder(1,"A",4350);
        Orderhandle or = new Orderhandle();
        or.handleOrder(order1);
        Order order2 = new Personalorder(2,"B",4350);
        or.handleOrder(order2);
    }
}
